/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package survey_dlt;
import java.sql.*;
import dbhandler.*;
import java.util.ArrayList;
import survey_dlt.dltquestion;
import survey_dlt.dltsurvey;
/**
 *
 * @author Swami
 */
public class delete {

 DBConnection db = new DBConnection();
        ArrayList<dltsurvey> dltsurvey=new ArrayList<dltsurvey>();
        ArrayList<dltquestion> dltquestion=new ArrayList<dltquestion>();
        
        ResultSet rs,rs1;
        Statement dbStatement;
        Connection dbCon;
    int id1,qid,sid,b;
   
    public ArrayList viewsurvey() throws SQLException, ClassNotFoundException         
    {
        String Query;
        
        
        
        Query = "select * from tbl_survey;";
        
        
       
        
        
        int ab = 0;
        db.connect();
        try {
            rs=db.customQuery(Query);
                      
            
           while(rs.next()){
                dltsurvey dlt=new dltsurvey();
                dlt.setSid(Integer.parseInt(rs.getString(1)));
                dlt.setTtl(rs.getString(5));
               /* dlt.setTypeId(Integer.parseInt(rs.getString(3)));
                evt.setPosteddt(rs.getString(4));*/
                
                dltsurvey.add(dlt);
                
                
            }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        
        return dltsurvey;
    }
    
      public ArrayList viewapprove() throws SQLException, ClassNotFoundException         
    {
        String Query;
        
        
        String s;
        Query = "select * from tbl_survey where approved_by IS NULL";
        
        
       
        
        
        int ab = 0;
        db.connect();
        try {
            rs=db.customQuery(Query);
                      
            
           while(rs.next())
           {
                dltsurvey dlt=new dltsurvey();
                dlt.setSid(Integer.parseInt(rs.getString(1)));
                dlt.setTtl(rs.getString(5));
               /* dlt.setTypeId(Integer.parseInt(rs.getString(3)));
                evt.setPosteddt(rs.getString(4));*/
                
                dltsurvey.add(dlt);
                
                
            }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        
        return dltsurvey;
    }
        
 public ArrayList viewquestion(String id) throws SQLException, ClassNotFoundException         
    {
        String Query1;   
        
        //int ab = 0;
     int  ab=Integer.parseInt(id);
        
       db.connect();
       Query1 = "select * from tbl_survey_detail where survey_id="+ab;
        
       try {
            rs1=db.customQuery(Query1);
                      
            
           while(rs1.next())
           {
                dltquestion dltq=new dltquestion();
                dltq.setSd_id(Integer.parseInt(rs1.getString(1)));
                dltq.setSid(Integer.parseInt(rs1.getString(2)));
                dltq.setQid(Integer.parseInt(rs1.getString(3)));
               dltq.setQue(rs1.getString(5));
                /* dlt.setTypeId(Integer.parseInt(rs.getString(3)));
                evt.setPosteddt(rs.getString(4));*/
                dltquestion.add(dltq);
            }
            
        } 
       catch (SQLException ex) {
           System.out.println("hi");
           ex.printStackTrace();
        }
        db.disconnect();
        
        
        
        return dltquestion;
    }
       
   
        public int dlt(int id)
{
   try
   {
   db.connect();
       boolean rs1;
       this.id1=id;
    rs1=db.executeQuery("delete  from tbl_survey where survey_id="+this.id1);

   }
catch (SQLException ex) {
        }
 db.disconnect();
 return 1;      
}
public static void main(String [] args) throws SQLException, ClassNotFoundException
{
    /*
    eventview evt=new eventview();
    ArrayList ab=new ArrayList();
}
*/
delete d=new delete();
ArrayList a=new ArrayList();
//d.approve("1",1);
//System.out.println(a);
}

public void dlt(String sid) {
       try
       {
           db.connect();
           boolean rs2;
           //this.qid=id;
           this.sid=Integer.parseInt(sid);
rs2=db.executeQuery("delete from tbl_survey_detail where sd_id="+this.sid);
       }
 catch (SQLException ex) {
        }
 db.disconnect();
   
    }

    public void approve(String a,int b) {
        try
       {
           
           db.connect();
           boolean rs2;
           //this.qid=id;
           this.id1=Integer.parseInt(a);
           this.b=b;
rs2=db.executeQuery("update tbl_survey set approved_by="+this.b+" where survey_id="+this.id1+"");
       }
 catch (SQLException ex) {
        }
 db.disconnect();
   
    }
   }
